// package com.cskaoyan.service;
//
// import com.cskaoyan.market.db.domain.*;
// import com.cskaoyan.market.db.mapper.*;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.stereotype.Service;
//
// import java.util.ArrayList;
// import java.util.HashMap;
// import java.util.List;
// import java.util.Map;
//
// @Service
// public class RefHomeServiceImpl implements HomeService {
//     @Autowired
//     MarketGoodsMapper goodsMapper;
//     @Autowired
//     MarketCategoryMapper categoryMapper;
//     @Autowired
//     MarketAdMapper adMapper;
//     @Autowired
//     MarketBrandMapper brandMapper;
//     @Autowired
//     MarketTopicMapper topicMapper;
//
//     @Override
//     public Map<String, List<?>> index() {
//         Map<String, List<?>> indexData = new HashMap<>();
//
//         MarketGoodsExample newGoodsExample = new MarketGoodsExample();
//         newGoodsExample.setOrderByClause("sort_order limit 6");
//         newGoodsExample.createCriteria().andIsNewEqualTo(true).andIsOnSaleEqualTo(true);
//         List<MarketGoods> newGoodsList = goodsMapper.selectByExampleSelective(newGoodsExample, MarketGoods.Column.id, MarketGoods.Column.name, MarketGoods.Column.brief, MarketGoods.Column.picUrl, MarketGoods.Column.isNew, MarketGoods.Column.isHot, MarketGoods.Column.counterPrice, MarketGoods.Column.retailPrice);
//         indexData.put("newGoodsList", newGoodsList);
//
//         // 有token优惠券列表为空，无token列表有值，业务逻辑不明
//         indexData.put("couponList", List.of());
//
//         MarketCategoryExample categoryExample = new MarketCategoryExample();
//         categoryExample.setOrderByClause("sort_order desc limit 10");
//         categoryExample.createCriteria().andPidEqualTo(0);
//         List<MarketCategory> channel = categoryMapper.selectByExampleSelective(categoryExample, MarketCategory.Column.id, MarketCategory.Column.name, MarketCategory.Column.iconUrl);
//         indexData.put("channel", channel);
//
//         MarketAdExample adExample = new MarketAdExample();
//         adExample.setOrderByClause("id limit 3");
//         adExample.createCriteria().andPositionEqualTo((byte) 1).andEnabledEqualTo(true);
//         List<MarketAd> banner = adMapper.selectByExample(adExample);
//         indexData.put("banner", banner);
//
//         MarketBrandExample brandExample = new MarketBrandExample();
//         brandExample.setOrderByClause("sort_order limit 4");
//         List<MarketBrand> brandList = brandMapper.selectByExampleSelective(brandExample, MarketBrand.Column.id, MarketBrand.Column.name, MarketBrand.Column.desc, MarketBrand.Column.picUrl, MarketBrand.Column.floorPrice);
//         indexData.put("brandList", brandList);
//
//         MarketGoodsExample hotGoodsExample = new MarketGoodsExample();
//         hotGoodsExample.setOrderByClause("sort_order limit 6");
//         hotGoodsExample.createCriteria().andIsHotEqualTo(true).andIsOnSaleEqualTo(true);
//         List<MarketGoods> hotGoodsList = goodsMapper.selectByExampleSelective(hotGoodsExample, MarketGoods.Column.id, MarketGoods.Column.name, MarketGoods.Column.brief, MarketGoods.Column.picUrl, MarketGoods.Column.isNew, MarketGoods.Column.isHot, MarketGoods.Column.counterPrice, MarketGoods.Column.retailPrice);
//         indexData.put("hotGoodsList", hotGoodsList);
//
//         MarketTopicExample topicExample = new MarketTopicExample();
//         topicExample.setOrderByClause("sort_order limit 4");
//         List<MarketTopic> topicList = topicMapper.selectByExampleSelective(topicExample, MarketTopic.Column.id, MarketTopic.Column.title, MarketTopic.Column.subtitle, MarketTopic.Column.price, MarketTopic.Column.readCount, MarketTopic.Column.picUrl);
//         indexData.put("topicList", topicList);
//
//         List<Map<String, Object>> floorGoodsList = new ArrayList<>();
//         for (int i = 0; i < 4; i++) {
//             Map<String, Object> floorGoods = new HashMap<>();
//             MarketCategory category = channel.get(i);
//             Integer id = category.getId();
//             String name = category.getName();
//             floorGoods.put("id", id);
//             floorGoods.put("name", name);
//             floorGoods.put("goodsList", getGoodsListByL1CategoryId(id));
//             floorGoodsList.add(floorGoods);
//         }
//         indexData.put("floorGoodsList", floorGoodsList);
//
//         return indexData;
//     }
//
//     private List<MarketGoods> getGoodsListByL1CategoryId(Integer l1CategoryId) {
//         MarketCategoryExample categoryExample = new MarketCategoryExample();
//         categoryExample.setOrderByClause("sort_order");
//         categoryExample.createCriteria().andPidEqualTo(l1CategoryId);
//         List<MarketCategory> l2CategoryList = categoryMapper.selectByExampleSelective(categoryExample, MarketCategory.Column.id);
//         List<Integer> l2CategoryIdList = new ArrayList<>();
//         for (MarketCategory category : l2CategoryList) {
//             l2CategoryIdList.add(category.getId());
//         }
//
//         MarketGoodsExample goodsExample = new MarketGoodsExample();
//         goodsExample.setOrderByClause("sort_order limit 4");
//         goodsExample.createCriteria().andCategoryIdIn(l2CategoryIdList).andIsOnSaleEqualTo(true);
//         return goodsMapper.selectByExampleSelective(goodsExample, MarketGoods.Column.id, MarketGoods.Column.name, MarketGoods.Column.brief, MarketGoods.Column.picUrl, MarketGoods.Column.isNew, MarketGoods.Column.isHot, MarketGoods.Column.counterPrice, MarketGoods.Column.retailPrice);
//     }
// }
